<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>代理商管理</cite></a>
    <a layadmin-event="back">返回代理商列表</a>
    <a><cite>参数配置</cite></a>
  </div>
</div>

<script type="text/html" template lay-url="admin/agents/{{layui.router().search.id}}/settings"
        lay-done="layui.data.done(d.data)">
  <div class="layui-fluid layui-form">
    <div class="layui-form">
      {{# var settings = d.data }}
      <div class="layui-card">
        <div class="layui-card-header">
          交易手续费设置
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">代理转售手续费率</label>
            <div class="layui-input-inline" style="width: 100px">
              <input type="number" lay-verify="required" class="layui-input" autocomplete="off"
                     name="pay_resale_agent_fee_rate" value="{{settings.pay_resale_agent_fee_rate || 0}}">
            </div>
            <div class="layui-inline layui-word-aux layui-form-mid">%</div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">普通订单交易手续费</label>
            <div class="layui-input-inline" style="width: 100px">
              <input type="number" lay-verify="required" class="layui-input" autocomplete="off"
                     name="pay_service_fee_rate" value="{{settings.pay_service_fee_rate || 0}}">
            </div>
            <div class="layui-inline layui-word-aux layui-form-mid">%</div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">转售订单交易手续费</label>
            <div class="layui-input-inline" style="width: 100px">
              <input type="number" lay-verify="required" class="layui-input" autocomplete="off"
                     name="pay_resale_service_fee_rate" value="{{settings.pay_resale_service_fee_rate || 0}}">
            </div>
            <div class="layui-inline layui-word-aux layui-form-mid">%</div>
          </div>
        </div>
      </div>


      <div class="layui-card">
        <div class="layui-card-header">
          支付通道选择
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">支付通道</label>
            <div class="layui-input-inline">
              <select name="pay_channel" lay-filter="pay_channel" class="layui-select">
                <option value="sdpay">杉德</option>
                <option value="adapay">汇付天下</option>
                <option value="yeepay">易宝</option>
              </select>
            </div>
          </div>
        </div>
      </div>

      <div class="layui-card pay_config_panel" id="panel_yeepay">
        <div class="layui-card-header">
          易宝
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">代理商户号</label>
            <div class="layui-input-inline" style="width: 300px">
              <input type="text" class="layui-input" autocomplete="off"
                     name="pay_merchant_no" value="{{settings.pay_merchant_no || ''}}">
            </div>
          </div>
        </div>

      </div>
      <div class="layui-card pay_config_panel" id="panel_adapay">
        <div class="layui-card-header">
          汇付天下
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">APPID</label>
            <div class="layui-input-inline" style="width: 300px">
              <input type="text" class="layui-input" autocomplete="off"
                     name="adapay_app_id" value="{{settings.adapay_app_id || ''}}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">API_KEY</label>
            <div class="layui-input-inline" style="width: 300px">
              <input type="text" class="layui-input" autocomplete="off"
                     name="adapay_api_key" value="{{settings.adapay_api_key || ''}}">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">商户RSA公钥</label>
            <div class="layui-input-inline" style="width: 600px">
                <textarea class="layui-textarea" autocomplete="off" name="adapay_rsa_public_key">{{settings.adapay_rsa_public_key || ''}}
                  </textarea>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">商户RSA私钥</label>
            <div class="layui-input-inline" style="width: 600px">
                <textarea class="layui-textarea" autocomplete="off" name="adapay_rsa_private_key">{{settings.adapay_rsa_private_key || ''}}
                  </textarea>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 170px">分账账号</label>
            <div class="layui-input-inline" style="width: 300px">
              <input type="text" class="layui-input" autocomplete="off"
                     name="adapay_divide_id" value="{{settings.adapay_divide_id || ''}}">
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          杉德(仅该通道支持钱包和二级交易)
        </div>
        <div class="layui-card-body">
          <div id="panel_sdpay" class="pay_config_panel">
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">商户编号</label>
              <div class="layui-input-inline" style="width: 300px">
                <input type="text" class="layui-input" autocomplete="off"
                       name="sdpay_merch_no" value="{{settings.sdpay_merch_no || ''}}">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label" style="width: 170px">商户RSA私钥</label>
              <div class="layui-input-inline" style="width: 600px">
                <textarea class="layui-textarea" autocomplete="off" name="sdpay_rsa_private_key">{{settings.sdpay_rsa_private_key || ''}}
                  </textarea>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div style="margin-bottom: 60px"></div>
        <div class="layui-form-item">
          <div class="layui-footer">
            <div class="layui-input-block">
              <input type="button" lay-submit lay-filter="submit_settings" value="保存"
                     class="layui-btn">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.done = function (obj) {
    layui.use([], function () {
      let $ = layui.$
        , form = layui.form
        , admin = layui.admin

      $('select[name="pay_channel"]').val(obj.pay_channel)
      form.render()

      // 提交
      form.on('submit(submit_settings)', function (data) {
        let field = data.field;
        console.log(field)
        admin.post('admin/agents/' + layui.router().search.id + '/settings', field, function () {
          layer.msg('保存成功', {
            offset: '15px'
            , icon: 1
            , time: 1000
          });
        });
      });
    })
    ;
  }
</script>
